package com.example.dllo.my36kr.ui.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.model.PeopleBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by CPC_272 on 16/8/27.
 */
public class PeopleAdapter extends BaseAdapter {
    private Context context;
    private List<PeopleBean.DataBean.DataBean1>dataBean1List;

    public PeopleAdapter(Context context) {
        this.context = context;
    }

    public void setDataBean1List(List<PeopleBean.DataBean.DataBean1> dataBean1List) {
        this.dataBean1List = dataBean1List;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dataBean1List!=null?dataBean1List.size():0;
    }

    @Override
    public Object getItem(int position) {
        return dataBean1List!=null?dataBean1List.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PeoPleHolder holder= null;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_people,parent,false);
            holder=new PeoPleHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder= (PeoPleHolder) convertView.getTag();
        }
        holder.tv_name.setText(dataBean1List.get(position).getUser().getName());
        Picasso.with(context).load(dataBean1List.get(position).getUser().getAvatar()).into(holder.img_people);
        List<String> mAttention = dataBean1List.get(position).getFocusIndustry();
        List<String> mPhase = dataBean1List.get(position).getInvestPhases();
        //它里面有空的 然后就先整个空的的字符串 !然后按条件往里面赋值
        String attention = "";
        String phase = "";
        //按集合判断卫视是在上面的还是在下面的,然后获取不同的数据
        for (int i = 0; i < mAttention.size(); i++) {
            attention = attention + " " + mAttention.get(i);
        }
        for (int i = 0; i < mPhase.size(); i++) {

            phase = phase + " " + mPhase.get(i);
        }
        //因为有的是有未赋值 我这里定义为CPC-272
        if (attention == "") {
            attention = "CPC-272";
        }

        if (phase == "") {
            phase = "CPC-272";
        }
        holder.tv_attention.setText(attention);
        holder.tv_phase.setText(phase);

        return convertView;
    }
    class PeoPleHolder {
        private TextView tv_name, tv_attention, tv_phase;
        private ImageView img_people;

        public PeoPleHolder(View view) {
            img_people = (ImageView) view.findViewById(R.id.imge_people);
            tv_name = (TextView) view.findViewById(R.id.name_people);
            tv_attention = (TextView) view.findViewById(R.id.tv_attention);
            tv_phase = (TextView) view.findViewById(R.id.tv_phase);
        }
    }
}
